 $.ajaxSetup({
    	dataType:'JSON',
    	error:function(){
    		$.message('消息提示','与服务器交互出错');
    	}
      });
      	$(function(){
          	/*
      		var priceTable = $('.priceTable').get(0);
      		var priceTableHeader = priceTable.innerHTML;
      		listType();
      		function listType(){
      			priceTable.innerHTML = priceTableHeader;
      			$.post('goodsData.php',function(o){
      				if(!o.status){
      					$.message('消息',o.info);
      				}else{
      					var goodes = o.goods;
      					for(var i=0; i<goodes.length; i++){
      						var goods = goodes[i];
      						var row = priceTable.insertRow(-1);
      						eachTypes(goods,row);
      					}
      				}
      			});
      		}
      		function eachTypes(goods,row){
      			var imgSpan = $('<span>',{html:goods.gName});			//名字
      			imgSpan.appendTo(row.insertCell(-1));
      			var img = $("<img src=img/"+goods.imgUrl+">");
      			img.appendTo(imgSpan);
      			
      			var nameSpan = $('<span>',{html:goods.gName});			//名字
      			nameSpan.appendTo(row.insertCell(-1));
      			
      			var stockSpan = $('<span>',{html:goods.stockPrice});			//名字
      			stockSpan.appendTo(row.insertCell(-1));
      			
      			var sellSpan = $('<span>',{html:goods.sellPrice});			//名字
      			sellSpan.appendTo(row.insertCell(-1));
      			
      			var sellStautsSpan = $('<span>',{html:goods.sellStauts});			//名字
      			sellStautsSpan.appendTo(row.insertCell(-1));
      			
      			var basicStautsSpan = $('<span>',{html:goods.basicStauts});			//名字
      			basicStautsSpan.appendTo(row.insertCell(-1));
      			
      			var typeSpan = $('<span>',{html:goods.tName});			//名字
      			typeSpan.appendTo(row.insertCell(-1));

      			var deleteSpan = $('<span>',{html:'删除'});			//删除
      			deleteSpan.click(function(){
      				$.confirm('删除确认',"你确定要删除["+type.name+"]?");
      				$('#confirmBtn').click(function(){
      					$.post('delGoods.php',{'id':type.id,'name':'type'},function(o){
      						if(!o.status){
      							$.message('消息',o.info);
      						}else{
      							listType();
      							dialog.modal('hide');
      						}
      					});
      				});
      			});
      			deleteSpan.addClass('deleteSpan').appendTo(row.insertCell(-1));
      		}








      		//var mes = "<?php @print($mes);?>";
      		if(mes == "添加商品类型成功"){
      			$.message('消息提示',mes);
      			$('#mesConfirm').click(function(){
      				location.href = 'typeList.php';
      			});
      		}
      		if(mes == "添加商品成功"){
      			$.message('消息提示',mes);
      			$('#mesConfirm').click(function(){
      				location.href = 'goodsList.php';
      			});
      		}
      		$('#nextCode').click(function(){
      			$('#codeImg').attr('src','img.php');
      		});
*/










    		

      	//goodsList
      		var goodsTable = $('.goodsTable').get(0);
      		var goodsTableHeader = goodsTable.innerHTML;
      		var pageNum;
      		var num;
      		function listGoods(pageNum){												//获取数据
      			goodsTable.innerHTML = goodsTableHeader;
      			$.post('goodsData.php',{'pageNum':pageNum},function(o){
      				if(!o.status){
      					$.message('消息',o.info);
      				}else{
      					var goodes = o.goods;
      					num = o.num;
      					for(var i=0; i<goodes.length; i++){
      						var goods = goodes[i];
      						var row = goodsTable.insertRow(-1);
      						eachGoods(goods,row);
      					}
      				}
      			});
      			if(pageNum <= 1){
      				$('#prevBtn').attr('disabled',true);
      			}else{
      				$('#prevBtn').attr('disabled',false);
      			}
      			if(pageNum >= num){
      				$('#nextBtn').attr('disabled',true);
      			}else{
      				$('#nextBtn').attr('disabled',false);
      			}
      		}
      		function eachGoods(goods,row){										//显示数据
      			var idSpan = $('<span>',{html:goods.gId});				//图片
      			idSpan.appendTo(row.insertCell(-1));
      			
      			var imgSpan = $('<span>');
      			imgSpan.appendTo(row.insertCell(-1));
      			var img = $("<img src='img/"+goods.imgUrl+"'>");
      			img.addClass('icon'+goods.gId);
      			img.appendTo(imgSpan);
      			$('.icon'+goods.gId).click(function(){
      				$.fileinput('修改图片');
      				$('.fileinput').fileinput({
      					uploadUrl:'updateImg.php',
      					removeLabel:'删除',
      					browseLabel:'浏览',
      					uploadLabel:'上传',
      					cancelLabel:'撤销',
      					uploadExtraData:{'pid':goods.gId}
      				});
      				$('.kv-fileinput-upload').click(function(){
      					setTimeout(function(){
      						$.post('imgData.php',{'id':goods.gId},function(o){
      							if(!o.status){
      								$.message('提示','获取数据失败');
      							}else{
      								$('.icon'+goods.gId).attr('src','img/'+o.src);
      								$('.modal').modal('hide');
      							}
      						});
      					},1000);
      				});
      			});

      			var nameSpan = $('<span>',{html:goods.gName});			//名字
      			nameSpan.editable({
      				placement:'bottom',
      				type:'text',
      				url:'ediGoods.php',
      				name:'name',
      				pk:goods.gId
      			});
      			nameSpan.appendTo(row.insertCell(-1));

      			var priceSpan = $('<span>',{html:goods.price});			//价格
      			priceSpan.editable({
      				placement:'bottom',
      				type:'text',
      				url:'ediGoods.php',
      				name:'price',
      				pk:goods.gId
      			});
      			priceSpan.appendTo(row.insertCell(-1));

      			var statusSpan = $('<span>',{html:goods.status});			//状态
      			statusSpan.editable({
      				placement:'bottom',
      				type:'select',
      				url:'ediGoods.php',
      				source:['正常','缺货'],
      				name:'status',
      				pk:goods.gId
      			});
      			statusSpan.appendTo(row.insertCell(-1));

      			var typeSpan = $('<span>',{html:goods.tName});			//类型
      			$.post('typeData.php',function(o){
      				if(!o.status){
      					$.message('消息提示',o.info);
      				}else{
      					var types = o.types;
      					for(var i=0; i<types.length; i++){
      						var type = types[i];
      						typeSpan.editable({
      							placement:'bottom',
      							type:'select',
      							url:'ediGoods.php',
      							source:[{'1':'水果'},{'2':'零食'},{'3':'家具'},{'4':'厨具'}],
      							name:'typeId',
      							pk:goods.gId
      						});
      					}
      				}
      			});
      			typeSpan.appendTo(row.insertCell(-1));

      			var deleteSpan = $('<span>',{html:'删除'});			//删除
      			deleteSpan.click(function(){
      				$.confirm('删除确认',"你确定要删除["+goods.gName+"]?");
      				$('#confirmBtn').click(function(){
      					$.post('delGoods.php',{'id':goods.gId,'name':'goods'},function(o){
      						if(!o.status){
      							$.message('消息',o.info);
      						}else{
      							listGoods(pageNum);
      							dialog.modal('hide');
      						}
      					});
      				});
      			});
      			deleteSpan.addClass('deleteSpan').appendTo(row.insertCell(-1));
      		}
      		function page(){										//分页
      			$('#firstBtn').click(function(){
      				pageNum = 1;
      				listGoods(pageNum);
      			}).click();
      			$('#prevBtn').click(function(){
      				pageNum --;
      				listGoods(pageNum);
      			});
      			$('#nextBtn').click(function(){
      				pageNum ++;
      				listGoods(pageNum);
      			});
      			$('#lastBtn').click(function(){
      				pageNum = num;
      				listGoods(pageNum);
      			});
      		}
      		page();

      	//typeList
      		var typeTable = $('.typeTable').get(0);
      		var typeTableHeader = typeTable.innerHTML;
      		listType();
      		function listType(){
      			typeTable.innerHTML = typeTableHeader;
      			$.post('typeData.php',function(o){
      				if(!o.status){
      					$.message('消息',o.info);
      				}else{
      					var types = o.types;
      					for(var i=0; i<types.length; i++){
      						var type = types[i];
      						var row = typeTable.insertRow(-1);
      						eachTypes(type,row);
      					}
      				}
      			});
      		}
      		function eachTypes(type,row){
      			var nameSpan = $('<span>',{html:type.name});			//名字
      			nameSpan.editable({
      				placement:'bottom',
      				type:'text',
      				url:'ediType.php',
      				name:'name',
      				pk:type.id
      			});
      			nameSpan.appendTo(row.insertCell(-1));

      			var deleteSpan = $('<span>',{html:'删除'});			//删除
      			deleteSpan.click(function(){
      				$.confirm('删除确认',"你确定要删除["+type.name+"]?");
      				$('#confirmBtn').click(function(){
      					$.post('delGoods.php',{'id':type.id,'name':'type'},function(o){
      						if(!o.status){
      							$.message('消息',o.info);
      						}else{
      							listType();
      							dialog.modal('hide');
      						}
      					});
      				});
      			});
      			deleteSpan.addClass('deleteSpan').appendTo(row.insertCell(-1));
      		}
      	 });




      		